import Vue from "vue";
import VueRouter from "vue-router";
import Login from "../views/login/index";
import layout from "@/layout/Index.vue";
import NotFound from "../views/404";
import Table from "../views/table/index";
import ProductAudit from "../views/ProductAudit/index";
import EnterpriseList from "../views/EnterpriseList/index";
import Category from "../views/Category/index";
import Authorization from "../views/Authorization/index";
Vue.use(VueRouter);

const asyncRouterMap = {
  path: "/layout",
  component: layout,
  children: [
    {
      path: "porcelainlist",
      component: Table,
    },
    {
      path: "productaudit",
      component: ProductAudit,
    },
    {
      path: "enterprise",
      component: EnterpriseList,
    },
    {
      path: "category",
      component: Category,
    },
    {
      path: "authorization",
      component: Authorization,
    },
  ],
};

const routes = [
  {
    path: "/",
    name: "login",
    component: Login,
  },
  {
    path: "/login",
    name: "login",
    component: Login,
  },
  {
    path: "",
    redirect: Login,
  },
  {
    path: "*",
    component: NotFound,
  },
  asyncRouterMap,
];

const router = new VueRouter({
  routes,
  mode: "hash",
});
// router.beforeEach((to, from, next) => {
//   if (JSON.parse(localStorage.getItem("category2")).length > 0) {
//     next();
//   } else {
//     this.push("/login");
//   }
// });

export default router;
